package ru.usu.gv.uicomponents;

import ru.usu.gv.uicomponents.viewitems.edge.IEdgeViewItem;
import ru.usu.gv.uicomponents.viewitems.edge.LineEdgeView;
import ru.usu.gv.uicomponents.viewitems.edge.SplineEdgeItem;
import ru.usu.gv.uicomponents.viewitems.edge.SplineTubeEdgeView;
import ru.usu.gv.uicomponents.viewitems.edge.TubeEdgeView;

import javax.media.j3d.Appearance;
import javax.media.j3d.TransformGroup;

import java.util.List;

/**
 * @author spupyrev
 * 03.11.2008
 */
public class UIEdgeTypeRegistry extends UIViewTypeRegistry<IUIEdgeType>
{
	private static abstract class UIEdgeType extends UIViewType implements IUIEdgeType
	{
		public UIEdgeType(String id, String title, String icon)
		{
			super(id, title, icon);
		}
	}

	private static final UIEdgeTypeRegistry instance = new UIEdgeTypeRegistry();

	private UIEdgeTypeRegistry()
	{
		addType(new UIEdgeType("line", "Линия", "images/lineEdge.png")
		{
			public IEdgeViewItem createEdgeViewItem(Appearance appearance, TransformGroup transformGroup, UIVertex v1, UIVertex v2)
			{
				return new LineEdgeView(appearance, transformGroup, v1, v2);
			}
		});

		addType(new UIEdgeType("spline", "Сплайн", "images/splineTubeEdge.png")
		{
			public IEdgeViewItem createEdgeViewItem(Appearance appearance, TransformGroup transformGroup, UIVertex v1, UIVertex v2)
			{
				return new SplineEdgeItem(appearance, transformGroup, v1, v2);
			}
		});

		addType(new UIEdgeType("tube", "Цилиндр", "images/edge.png")
		{
			public IEdgeViewItem createEdgeViewItem(Appearance appearance, TransformGroup transformGroup, UIVertex v1, UIVertex v2)
			{
				return new TubeEdgeView(appearance, transformGroup, v1, v2);
			}
		});
		
		addType(new UIEdgeType("splinetube", "SplineTube", "images/splineTubeEdge.png")
		{
			public IEdgeViewItem createEdgeViewItem(Appearance appearance, TransformGroup transformGroup, UIVertex v1, UIVertex v2)
			{
				return new SplineTubeEdgeView(appearance, transformGroup, v1, v2);
			}
		});
	}

	public static IEdgeViewItem createVertexViewItem(String edgeTypeId, Appearance appearance, TransformGroup transformGroup, UIVertex v1, UIVertex v2)
	{
		IUIEdgeType vertexType = findEdgeType(edgeTypeId);
		return vertexType.createEdgeViewItem(appearance, transformGroup, v1, v2);
	}

	public static List<String> getEdgeTypeIds()
	{
		return instance.getViewTypeIds();
	}

	public static IUIEdgeType findEdgeType(String edgeTypeId)
	{
		return instance.findViewType(edgeTypeId);
	}

}
